package entity

import (
	"shqsoft.cn/pasnj/base"
	//"strconv"
	"time"

	"github.com/jinzhu/gorm"
)

//对私贷款批量认定
type IndiLoanDiviPl_EJFH struct {
	ID          int        `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	SFZH        string     `gorm:"column:SFZH"`            //借据号
	KHMC        string     `gorm:"column:KHMC"`            //客户姓名
	KHJL1       string     `gorm:"column:KHJL1"`           //客户经理1
	ZB1         int        `gorm:"column:ZB1"`             //占比1
	KHJL2       string     `gorm:"column:KHJL2"`           //客户经理2
	ZB2         *int       `gorm:"column:ZB2"`             //占比2
	KHJL3       string     `gorm:"column:KHJL3"`           //客户经理3
	ZB3         *int       `gorm:"column:ZB3";`            //占比3
	KHJL4       string     `gorm:"column:KHJL4"`           //客户经理4
	ZB4         *int       `gorm:"column:ZB4";`            //占比4
	KHJL5       string     `gorm:"column:KHJL5"`           //客户经理5
	ZB5         *int       `gorm:"column:ZB5";`            //占比5
	CLJG        string     `gorm:"column:CLJG"`            //导入结果
	KSSJ        *time.Time `gorm:"column:KSSJ";type:date;` //分户日期
	ZJHM        string     `gorm:"column:ZJHM"`            //证件号码
	ISTZ        string     `gorm:"column:ISTZ"`            //批量认定处理方式：0 处理未分配 1调整已分配
	ISTZCaption string     `gorm:"-"`
}

//TableName 对私贷款认定分户情况
func (IndiLoanDiviPl_EJFH) TableName() string {
	return "T_INDI_ACCO_PL_DTIP_EJFH"
}

func (pl *IndiLoanDiviPl_EJFH) AfterFind() (err error) {
	if pl.ISTZ == "0" {
		pl.ISTZCaption = "批量处理未分配的个贷客户"
	} else if pl.ISTZ == "1" {
		pl.ISTZCaption = "批量调整已分配的个贷客户"
	}
	return
}

//IndiLoanAfterImport 导入后执行分户处理
func IndiLoanDiviPl_EJFHAfterImport(tx *gorm.DB, params map[string]string) (err error) {
	ISTZ := params["ISTZ"]
	if ISTZ == "0" {
		tx.Exec("exec UP_INDI_LOAN_PL_CL_EJFH")
	} else if ISTZ == "1" {
		tx.Exec("exec UP_INDI_LOAN_PL_TZ_EJFH")
	}
	return nil
}

func IndiLoanDiviPl_EJFHEF() base.EntityFunc {
	return func() interface{} {
		entity := IndiLoanDiviPl_EJFH{}
		return &entity
	}
}
func IndiLoanDiviPl_EJFHESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []IndiLoanDiviPl_EJFH
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("IndiLoanDiviPl_EJFH", base.NewDefaultDao(IndiLoanDiviPl_EJFHEF(), IndiLoanDiviPl_EJFHESF(), nil))
	base.SetAfterCallBack("IndiLoanDiviPl_EJFH", IndiLoanDiviPl_EJFHAfterImport)
}
